#include <limits.h>  // INT_MIN,INT_MAX
#include <math.h>    // abs,pow

#include <algorithm>      // sort
#include <iostream>       // cout,cin
#include <numeric>        // accumulate
#include <string>         // string
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <vector>         // vector

using namespace std;

// 如果x是2的幂则返回True，否则返回False
bool IsPowerOf2(int x) { return (x & (x - 1)) == 0; }

class Solution {
   public:
    int lengthOfLongestSubstring(string s) {
        int size = s.size();

        unordered_map<char, int> count;

        int l = 0;
        int r = 0;
        int ans = 0;

        while (r < size) {
            count[s[r]] += 1;
            while (count[s[r]] > 1) {
                count[s[l]] -= 1;
                l++;
            }
            r++;
            ans = max(ans, r - l);
        }

        return ans;
    }
};

int main() {
    Solution solution;
    return 0;
}